define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'classes/student/index' + location.search,
                    add_url: 'classes/student/add',
                    edit_url: 'classes/student/edit',
                    del_url: 'classes/student/del',
                    multi_url: 'classes/student/multi',
                    dragsort_url: '',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                sortOrder: 'asc',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', sortable: true, title: __('Id'),operate: false},
                        {field: 'student_number', title: __('studentNumber')},
                        // {field: 'avatar', title: __('Avatar'),operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'nickname', title: __('Realname')},
                        {field: 'mobile', title: '手机号',operate: false},
                        {field: 'gender', title: __('Gender'),operate: false, formatter: function(value, row, index){
                                return value == 1 ? '男' : (value == 2 ? '女' : '未知')
                            }},
                        // {field: 'classs',title: __('Classes'), operate: false},
                        {field: 'verify_status', title: '审核状态',searchList: {"1": __('审核通过'), "0": __('待审核')}, formatter: function(value, row, index){
                                return value == 1 ? '通过' : (value == 2 ? '拒绝' : '待审核')
                            }},
                        {field: 'createtime', sortable: true, title: __('Createtime'), operate: false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons:[
                                {
                                    name: '通过',
                                    text: '通过',
                                    confirm: '确认通过？',
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    url: 'classes/student/restore',
                                    visible:function (row) {
                                        if(row.verify_status != 1)
                                        {
                                            return true;
                                        }
                                        return false;
                                    },
                                    refresh: true,
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
                search: false,
                commonSearch: true
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {


            /*$("#c-classes_id").data("params", function(){
                return {"custom": {"admin_id": $("#c-admin_id").val(),'status':'normal' }};
            });*/
            Controller.api.bindevent();

        },
        edit: function () {

            /*$("#c-classes_id").data("params", function(){
                return {"custom": {"admin_id": $("#c-admin_id").val(),'status':'normal' }};
            });*/
            Controller.api.bindevent();

        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };

    return Controller;
});